PREFIX ?= /usr

LIBRARY = libzee-scgi.so

SRC = Request.vala Server.vala
PKGS = --pkg=gio-2.0

VALAC = valac
VALACOPTS = -g --library=libzee-scgi -X -shared -H libzee-scgi.h

all: $(LIBRARY)

$(LIBRARY):
	@echo "Invokig valac..."
	@$(VALAC) $(VALACOPTS) $(SRC) -o $(LIBRARY) $(PKGS)

install: $(LIBRARY) libzee-scgi.deps
	@echo "Installing..."
	@install -m 755 -d $(INSTDIR)/$(PREFIX)/lib/pkgconfig/ $(INSTDIR)/$(PREFIX)/include/ $(INSTDIR)/$(PREFIX)/share/vala/vapi
	@install -m 755 $(LIBRARY) $(INSTDIR)/$(PREFIX)/lib/
	@install -m 644 libzee-scgi.h $(INSTDIR)/$(PREFIX)/include/
	@install -m 644 libzee-scgi.vapi $(INSTDIR)/$(PREFIX)/share/vala/vapi
	@install -m 644 libzee-scgi.deps $(INSTDIR)/$(PREFIX)/share/vala/vapi
	@sed -e 's/@LIBDIR@/\$(PREFIX)\/lib/' -e 's/@INCLUDEDIR@/\$(PREFIX)\/include/' libzee-scgi.pc.in > $(INSTDIR)/$(PREFIX)/lib/pkgconfig/libzee-scgi.pc

uninstall:
	@echo "Uninstalling..."
	@rm $(INSTDIR)/$(PREFIX)/lib/$(LIBRARY)
	@rm $(INSTDIR)/$(PREFIX)/include/libzee-scgi.h
	@rm $(INSTDIR)/$(PREFIX)/share/vala/vapi/libzee-scgi.vapi
	@rm $(INSTDIR)/$(PREFIX)/lib/pkgconfig/libzee-scgi.pc

clean:
	@echo "Cleaning..."
	@rm -v -fr *~ *.c $(LIBRARY) *.vapi *.h

.PHONY: clean all install
